<?php

namespace App\Service\Index\v1_2_7;

use App\Model\CoinLog;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 速配奖励提示列表
 */
class RewardTipsService extends BaseService
{
    public function handle()
    {
        $ret['list'] = $this->getLogs(50);
        return $ret;
    }

    function getLogs($limit = 10)
    {
        $where = ['from' => CoinLog::FROM_DAILY_FREE_RECHARGE];
        $logs = CoinLog::where($where)->orderBy('id', 'desc')->limit($limit)->pluck('coin', 'user_id')->toArray();
        $hostIds = array_keys($logs);
        $profiles = UserProfile::getUsersProfile($hostIds, true);
        $list = [];
        foreach ($logs as $userId => $coin) {
            $nick = $profiles[$userId]['nick_name'];
            $nick = mb_substr($nick, 0, 1) . "**" . mb_substr($nick, -1);
            $list[] = "恭喜 {$nick} 获得速配充值奖励{$coin}金币";
        }
        return $list;
    }
}
